/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.controller;

import admin.action.ActionRemove;
import admin.action.IAction;
import java.util.List;
import javax.annotation.PostConstruct;

/**
 *
 * @author Nothing4ever
 */
public abstract class WrapperListController<T> extends WrapperController<T> {

    private IAction<T> action;
    private List<T> listData;
    private Class<T> type;
    private List<T> filterList;
    
    public WrapperListController() {
        super();
        
//        this.checkLogin();
    }

    public Class<T> getType() {
        return type;
    }

    @PostConstruct
    public void findAll() {
        listData = getProvider().findAll();
    }

    public List<T> getListData() {
//        if (listData == null) {
//            listData = findAll();
//        }
        return listData;
    }

    public void prepareRemove() {
        setAction(new ActionRemove<T>(getProvider(), getRemoveObject()));
    }

    public void remove() {
        getAction().doAction();
        findAll();
    }

    public abstract T getRemoveObject();

    public List<T> getFilterList() {
        return filterList;
    }

    public void setFilterList(List<T> filterList) {
        this.filterList = filterList;
    }

    protected IAction<T> getAction() {
        return action;
    }

    protected void setAction(IAction<T> action) {
        this.action = action;
    }
    
}
